/*
 * @Description: 正则表达式常量
 * @Version: 1.0
 * @Author: 琴时
 * @Date: 2021-09-02 09:17:05
 * @LastEditors: 琴时
 * @LastEditTime: 2021-09-02 20:37:05
 */
export const RegularExpression = {
    NUMBER: { describe: "数字", rule: { pattern: /^\d*$/, message: "请输入数字" } },
    FEI_NUMBER: { describe: "非数字", rule: { pattern: /^\D*$/, message: "请输入非数字" } },
    CN_CHARACTERS: { describe: "汉字", rule: { pattern: /^[\u4e00-\u9fa5]*$/, message: "请输入汉字" } },
    EN_CHARACTERS: { describe: "英文", rule: { pattern: /^[A-Za-z]*$/, message: "请输入英文" } },
    EN_NUMBER_UNDERLINE: { describe: "英文、数字或下划线", rule: { pattern: /^[A-Za-z0-9_]*$/, message: "请输入英文、数字或下划线" } },
    EN_NUMBER: { describe: "英文或数字", rule: { pattern: /^[A-Za-z0-9]*$/, message: "请输入英文或数字" } },
    EMAIL: { describe: "邮箱地址", rule: { pattern: /^([A-Za-z\d]+[-|_|\.]?)+[A-Za-z\d]@([A-Za-z\d]+(-[A-Za-z\d]+)?\.)+[a-zA-Z]{2,3}$/, message: "请输入正确的邮箱地址" } },
    MOBILE_PHONE_NUMBER: { describe: "手机号码", rule: { pattern: /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d|)\d{8}$/, message: "请输入正确的手机号码" } },
    PHONE_NUMBER: { describe: "电话号码", rule: { pattern: /^(0[0-9]{2}-[0-9]{8}(-[0-9]{1,4})?$)|(0[0-9]{3}-[0-9]{7,8}(-[0-9]{1,4})?$)/, message: "请输入正确的电话号码" } },
    IDCARD: { describe: "身份证号码", rule: { pattern: /(^[1-9]{1}[0-9]{14}$)|(^[1-9]{1}[0-9]{16}[0-9X]{1}$)/, message: "请输入正确的身份证号，字母应为大写" } },
    QQ: { describe: "QQ号码", rule: { pattern: /^[1-9][0-9]{4,15}$/, message: "请输入正确的QQ号" } },
    POSTAL_CODE: { describe: "邮政编码", rule: { pattern: /^[1-9][0-9]{5}$/, message: "请输入正确的邮政编码" } }
}

/**
 * @description: 正则校验函数
 * @param {*} 所校验的值
 * @return {*} bool->符合：true,不符合：false
 * @author: 琴时
 */
export const RegularAction = {
    regNumber: (params) => {
        /* 校验数组 */
        const reg = RegularExpression.NUMBER.rule.pattern
        return reg.test(params)
    },
    regFeiNumber: (params) => {
        /* 校验非数字 */
        const reg = RegularExpression.FEI_NUMBER.rule.pattern
        return reg.test(params)
    },
    regCnChart: (params) => {
        /* 校验中文 */
        const reg = RegularExpression.CN_CHARACTERS.rule.pattern
        return reg.test(params)
    },
    regEnChart: (params) => {
        /* 校验英文 */
        const reg = RegularExpression.EN_CHARACTERS.rule.pattern
        return reg.test(params)
    },
    regEnNumber: (params) => {
        /* 英文、数字 */
        const reg = RegularExpression.EN_NUMBER.rule.pattern
        return reg.test(params)
    },
    regEnNumberUnderline: (params) => {
        /* 英文、数字或下划线 */
        const reg = RegularExpression.EN_NUMBER_UNDERLINE.rule.pattern
        return reg.test(params)
    },
    regPhone: (params) => {
        /* 电话 */
        const reg = RegularExpression.PHONE_NUMBER.rule.pattern
        return reg.test(params)
    },
    regMobile: (params) => {
        /* 手机 */
        const reg = RegularExpression.MOBILE_PHONE_NUMBER.rule.pattern
        return reg.test(params)
    },
    regEmail: (params) => {
        /* 邮箱 */
        const reg = RegularExpression.EMAIL.rule.pattern
        return reg.test(params)
    },
    regQQ: (params) => {
        /* QQ */
        const reg = RegularExpression.QQ.rule.pattern
        return reg.test(params)
    },
    regPostalCode: (params) => {
        /* 邮编 */
        const reg = RegularExpression.POSTAL_CODE.rule.pattern
        return reg.test(params)
    },
    reqIDCard: (params) => {
        /* 身份证号码 */
        const reg = RegularExpression.IDCARD.rule.pattern
        return reg.test(params)
    },

}

/**
 * 测试用例
 * 将src/index.js底部执行函数:selectTest(params)的实参params改为 6
 * 直接无法测试，请使用npm run dev或者去掉 export 使用node运行当前界面测试即可
 */

console.log('测试校验手机号:',RegularAction.regMobile('17322436183'))